﻿using Comsenz.Base;
using Comsenz.Discuz.Configs;
using Lbb.Web;
using Comsenz.Base.Exceptions;

namespace Comsenz.Discuz
{
    /// <summary>
    /// Discuz Api通讯器
    /// </summary>
    /// <author>Chiron</author>
    internal class DiscuzApiCommunicator : CommunicatorBase
    {
        public const string CLIENT_RELEASE = "2012-06-30";

        protected override string MakeRequestdata(string module, string action, string argStr, string extra)
        {
            var config = DiscuzConfig.Instance.CurrentConnectConfig;
            return "mod=extapis&module=" + module +
                "&action=" + action +
                "&inajax=2&release=" + CLIENT_RELEASE +
                "&input=" + argStr +
                "&appid=" + config.AppId +
                (string.IsNullOrEmpty(extra) ? string.Empty : ("&" + extra));
        }

        protected override string Invoker(string postdata)
        {
            if (!DiscuzConfig.Instance.Enabled) throw new ServiceIsClosedException("Discuz已被禁用!请在配置文件中开启它.");
            var config = DiscuzConfig.Instance.CurrentConnectConfig;
            return HttpHelper.HttpGet(config.ApiUri, postdata);
        }

        protected override string GetConnectKey()
        {
            return DiscuzConfig.Instance.CurrentConnectConfig.ConnectKey;
        }
    }
}
